home *** CD-ROM | disk | FTP | other *** search
- Imports System.ComponentModel
-
- ' a textbox control that lets you open the FileOpen dialog
-
- '<ToolboxBitmap("E:\Program Files\Microsoft Visual Studio .NET\Common7\Graphics\icons\Computer\Disk08.ico")> _
- Public Class FileTextBox
- Inherits System.Windows.Forms.UserControl
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'UserControl overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents txtFilename As System.Windows.Forms.TextBox
- Friend WithEvents btnBrowse As System.Windows.Forms.Button
- Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.btnBrowse = New System.Windows.Forms.Button()
- Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
- Me.txtFilename = New System.Windows.Forms.TextBox()
- Me.SuspendLayout()
- '
- 'btnBrowse
- '
- Me.btnBrowse.Location = New System.Drawing.Point(256, 8)
- Me.btnBrowse.Name = "btnBrowse"
- Me.btnBrowse.Size = New System.Drawing.Size(24, 24)
- Me.btnBrowse.TabIndex = 1
- Me.btnBrowse.Text = "..."
- '
- 'OpenFileDialog1
- '
- Me.OpenFileDialog1.Filter = "All Files (*.*)|*.*"
- '
- 'txtFilename
- '
- Me.txtFilename.Location = New System.Drawing.Point(8, 8)
- Me.txtFilename.Name = "txtFilename"
- Me.txtFilename.Size = New System.Drawing.Size(248, 20)
- Me.txtFilename.TabIndex = 0
- Me.txtFilename.Text = ""
- '
- 'FileTextBox
- '
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnBrowse, Me.txtFilename})
- Me.Name = "FileTextBox"
- Me.Size = New System.Drawing.Size(296, 40)
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- '----------------------------------------------------------------
- ' The Filename property
- ' (a wrapper on the txtFilename.Text property)
- '----------------------------------------------------------------
-
- <Description("The filename as it appears in the textbox")> _
- Property Filename() As String
- Get
- Return Me.txtFilename.Text
- End Get
- Set(ByVal Value As String)
- Me.txtFilename.Text = Value
- End Set
- End Property
-
- '----------------------------------------------------------------
- ' The Filter property
- ' (a wrapper on the OpenFileDialog property with same name)
- '----------------------------------------------------------------
-
- <Description("The list of file filters"), DefaultValue("All files (*.*)|*.*")> _
- Property Filter() As String
- Get
- Return OpenFileDialog1.Filter
- End Get
- Set(ByVal Value As String)
- OpenFileDialog1.Filter = Value
- End Set
- End Property
-
- '----------------------------------------------------------------
- ' The Filter property
- ' (a wrapper on the OpenFileDialog property with same name)
- '----------------------------------------------------------------
-
- Property FilterIndex() As Integer
- Get
- Return OpenFileDialog1.FilterIndex
- End Get
- Set(ByVal Value As Integer)
- OpenFileDialog1.FilterIndex = Value
- End Set
- End Property
-
- '----------------------------------------------------------------
- ' The ForeColor property
- ' (a wrapper on the TextBox property with same name)
- '----------------------------------------------------------------
-
- Shadows Property ForeColor() As Color
- Get
- Return txtFilename.ForeColor
- End Get
- Set(ByVal Value As Color)
- txtFilename.ForeColor = Value
- End Set
- End Property
-
- ' Resetxxx and ShouldSerializexxxx methods
-
- Shadows Sub ResetForeColor()
- Me.ForeColor = SystemColors.ControlText
- End Sub
-
- Function ShouldSerializeForeColor() As Boolean
- Return Not Me.ForeColor.Equals(SystemColors.ControlText)
- End Function
-
- '----------------------------------------------------------------
- ' The BackColor property
- ' (a wrapper on the TextBox property with same name)
- '----------------------------------------------------------------
-
- Shadows Property BackColor() As Color
- Get
- Return txtFilename.BackColor
- End Get
- Set(ByVal Value As Color)
- txtFilename.BackColor = Value
- End Set
- End Property
-
- ' Resetxxx and ShouldSerializexxxx methods
-
- Shadows Sub ResetBackColor()
- Me.BackColor = SystemColors.Window
- End Sub
-
- Function ShouldSerializeBackColor() As Boolean
- Return Not Me.BackColor.Equals(SystemColors.Window)
- End Function
-
- '----------------------------------------------------------------
- ' The ShowDialog method
- ' (a wrapper on the OpenFileDialog method with same name)
- '----------------------------------------------------------------
-
- Function ShowDialog() As DialogResult
- ' show the OpenFile dialog, return the result
- ShowDialog = OpenFileDialog1.ShowDialog
- ' If the result is ok, assign the filename to the TextBox
- If ShowDialog = DialogResult.OK Then
- txtFilename.Text = OpenFileDialog1.FileName
- End If
- End Function
-
- ' open the FileOpen dialog when the browse button is clicked
-
- Private Sub btnBrowse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
- ShowDialog()
- End Sub
-
- ' Expose the TextChanged event to the outside, under another name
- Event FilenameChanged(ByVal sender As Object, ByVal e As System.EventArgs)
-
- Private Sub txtFilename_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFilename.TextChanged
- RaiseEvent FilenameChanged(Me, e)
- End Sub
-
- ' Expose the two OpenFileDialog events to the outside
-
- Event FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
- Event HelpRequest(ByVal sender As Object, ByVal e As System.EventArgs)
-
- Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
- OnFileOk(e)
- End Sub
-
- Private Sub OpenFileDialog1_HelpRequest(ByVal sender As Object, ByVal e As System.EventArgs) Handles OpenFileDialog1.HelpRequest
- OnHelpRequest(e)
- End Sub
-
- Protected Overridable Sub OnFileOk(ByVal e As System.ComponentModel.CancelEventArgs)
- RaiseEvent FileOk(Me, e)
- End Sub
-
- Protected Overridable Sub OnHelpRequest(ByVal e As EventArgs)
- RaiseEvent HelpRequest(Me, e)
- End Sub
-
-
- Private Sub FileTextBox_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
- RedrawControls()
- End Sub
-
- Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
- ' Let the base control update the TextBox control.
- MyBase.OnFontChanged(e)
- ' Now we can redraw controls if necessary.
- RedrawControls()
- End Sub
-
- ' correctly resize child controls
-
- Private Sub RedrawControls()
- ' This is the width of the control.
- Dim width As Integer = Me.ClientRectangle.Width
- ' This is the (desired) height of the control.
- Dim btnSide As Integer = txtFilename.Height
-
- ' Adjust the height of the UserControl if necessary.
- If Me.ClientRectangle.Height <> btnSide Then
- ' Resize the UserControl.
- Me.SetClientSizeCore(Me.ClientRectangle.Width, btnSide)
- ' the above statement fires a nested Resize event, so exit right now.
- Exit Sub
- End If
-
- ' Resize the constituent controls.
- txtFilename.SetBounds(0, 0, width - btnSide, btnSide)
- btnBrowse.SetBounds(width - btnSide, 0, btnSide, btnSide)
- End Sub
-
- '----------------------------------------------------------------
- ' Override properties in order to hide them in the Property window
- '----------------------------------------------------------------
-
- <Browsable(False)> _
- Shadows Property AutoScroll() As Boolean
- Get
- If Not Me.DesignMode Then
- Throw New NotImplementedException()
- End If
- End Get
- Set(ByVal Value As Boolean)
- If Not Me.DesignMode Then
- Throw New NotImplementedException()
- End If
- End Set
- End Property
-
- ' ensure that all controls point to the same context menu
-
- Overrides Property ContextMenu() As ContextMenu
- Get
- Return MyBase.ContextMenu
- End Get
- Set(ByVal Value As ContextMenu)
- MyBase.ContextMenu = Value
- ' Propagate the new value to constituent controls.
- Dim ctrl As Control
- For Each ctrl In Me.Controls
- ctrl.ContextMenu = Me.ContextMenu
- Next
- End Set
- End Property
-
- ' change the style of the button when the Enabled property changes
-
- Private Sub FileTextBox_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.EnabledChanged
- If Me.Enabled Then
- btnBrowse.FlatStyle = FlatStyle.Standard
- Else
- btnBrowse.FlatStyle = FlatStyle.Flat
- End If
- End Sub
- End Class
-